class Psutils < Formula
  include Language::Python::Virtualenv

  desc "Utilities for manipulating PostScript documents"
  homepage "https://github.com/rrthomas/psutils"
  url "https://files.pythonhosted.org/packages/a8/95/8303c0d17381d43d3ec5fdc0d2466e3043864d3697fca438d9bc0eca148c/pspdfutils-3.3.0.tar.gz"
  sha256 "585deacf22639c7d8b956e7894fb1f4290df25f051a6a99b225682c573912132"
  license "GPL-3.0-or-later"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_ventura:  "c5372359859f0d41d91ad663602403e27d4028659df735c3915139920dd7ef00"
    sha256 cellar: :any_skip_relocation, arm64_monterey: "35d4017213a848825c73ba3305fb312c89114f09815ef648322ec0fea8053501"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "c05040fd72b43054235c3d1ea03c1d516b0ce25b012420a915a8b3a8d0117296"
    sha256 cellar: :any_skip_relocation, ventura:        "ec0eef3610dbfdf329d6598279457fcab27f99e64933292bbe1746684d96baab"
    sha256 cellar: :any_skip_relocation, monterey:       "dd214b47dff3b309f41bb9d6ca83226997b9517eec6e38ff812416e3a1f6cf04"
    sha256 cellar: :any_skip_relocation, big_sur:        "16bdb9c0d7894408b8cd54fa3eee279146cdf2e4674c435c9bf673c033fb6eaf"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "2a4598c61ab8ca79db08045673e5e987fa3898dcf28d7be1013573d774159255"
  end

  depends_on "libpaper"
  depends_on "python@3.11"

  resource "puremagic" do
    url "https://files.pythonhosted.org/packages/50/bb/c9860ce714ce2147b6168fdf817e67c3be6eabc822fab5ef41cc52bafdec/puremagic-1.15.tar.gz"
    sha256 "6e46aa78113a466abc9f69e6e8a4ce90eb57d908dafb809597012621061462bd"
  end

  resource "pypdf" do
    url "https://files.pythonhosted.org/packages/7b/3e/1de6748e2f789cddcc3724caccc4876a862af563def5cbfd760566c9e828/pypdf-3.16.0.tar.gz"
    sha256 "71fd274f5e02c7122f688f5b2609407d5dd92ecb4140d498108fc94ea9573800"
  end

  def install
    virtualenv_install_with_resources
  end

  test do
    resource "homebrew-test-ps" do
      url "https://raw.githubusercontent.com/rrthomas/psutils/e00061c21e114d80fbd5073a4509164f3799cc24/tests/test-files/psbook/3/expected.ps"
      sha256 "bf3f1b708c3e6a70d0f28af55b3b511d2528b98c2a1537674439565cecf0aed6"
    end
    resource("homebrew-test-ps").stage testpath

    expected_psbook_output = "[4] [1] [2] [3] \nWrote 4 pages\n"
    assert_equal expected_psbook_output, shell_output("#{bin}/psbook expected.ps book.ps 2>&1")

    expected_psnup_output = "[1,2] [3,4] \nWrote 2 pages\n"
    assert_equal expected_psnup_output, shell_output("#{bin}/psnup -2 expected.ps nup.ps 2>&1")

    expected_psselect_output = "[1] \nWrote 1 pages\n"
    assert_equal expected_psselect_output, shell_output("#{bin}/psselect -p1 expected.ps test2.ps 2>&1")
  end
end
